home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCSRC.ZIP / LINKLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1988-01-15  |  2KB  |  54 lines

  1.                                 (* Chapter 12 - Program 5 *)
  2. program Linked_List_Example;
  3.  
  4. type Next_Pointer = ^Full_Name;
  5.  
  6.      Full_Name = record
  7.        First_Name : string[12];
  8.        Initial    : char;
  9.        Last_Name  : string[15];
  10.        Next       : Next_Pointer;
  11.      end;
  12.  
  13. var  Start_Of_List : Next_Pointer;
  14.      Place_In_List : Next_Pointer;
  15.      Temp_Place    : Next_Pointer;
  16.      Index         : integer;
  17.  
  18. begin  (* main program *)
  19.                        (* generate the first name in the list *)
  20.    New(Place_In_List);
  21.    Start_Of_List := Place_In_List;
  22.    Place_In_List^.First_Name := 'John';
  23.    Place_In_List^.Initial := 'Q';
  24.    Place_In_List^.Last_Name := 'Doe';
  25.    Place_In_List^.Next := nil;
  26.                        (* generate another name in the list *)
  27.    Temp_Place := Place_In_List;
  28.    New(Place_In_List);
  29.    Temp_Place^.Next := Place_In_List;
  30.    Place_In_List^.First_Name := 'Mary';
  31.    Place_In_List^.Initial := 'R';
  32.    Place_In_List^.Last_Name := 'Johnson';
  33.    Place_In_List^.Next := nil;
  34.                   (* add 10 more names to complete the list *)
  35.    for Index := 1 to 10 do begin
  36.       Temp_Place := Place_In_List;
  37.       New(Place_In_List);
  38.       Temp_Place^.Next := Place_In_List;
  39.       Place_In_List^.First_Name := 'William';
  40.       Place_In_List^.Initial := 'S';
  41.       Place_In_List^.Last_Name := 'Jones';
  42.       Place_In_List^.Next := nil;
  43.    end;
  44.                    (* display the list on the video monitor *)
  45.    Place_In_List := Start_Of_List;
  46.    repeat
  47.       Write(Place_In_List^.First_Name);
  48.       Write(' ',Place_In_List^.Initial);
  49.       Writeln(' ',Place_In_List^.Last_Name);
  50.       Temp_Place := Place_In_List;
  51.       Place_In_List := Place_In_List^.Next;
  52.    until Temp_Place^.Next = nil;
  53. end.  (* of main program *)
  54.